<!--附件-->
<template>
  <div class='home' v-if="attachmentShow" style="min-height: 200px;">
    <!--头部提示-->
    <el-row>
      <el-col :span="12"><div class="grid-content bg-purple-light" style="margin-top: 10px;">
        <h4 class="wf_h">附件列表</h4>
      </div>
      </el-col>
    </el-row>
    <!--数据展示-->
    <el-row>
      <el-table
        :data="attachmentTableData"
        style="width: 100%">
        <el-table-column prop="taskDisplayName" label="任务名" width="180"></el-table-column>
        <el-table-column prop="showResult" label="审核结果" width="180"></el-table-column>
        <el-table-column prop="opinion" label="审核意见"></el-table-column>
        <el-table-column prop="approvalDatetime" label="审核时间" width="180"></el-table-column>
      </el-table>
    </el-row>
  </div>
</template>

<script>
  /* ajax请求 */
  import * as kk from '@/utils/k-utils'

  export default {
    name: 'Attachment',
    props: {
      // 保存列表页面传过来的数据，子组件接受父组件数据
      param: {
        type: Object,
        required: true
      }
    },
    data() {
      return {
        attachmentShow: false, // 是否开启了附件上传功能
        attachmentTableData: [],
        first: true
      }
    },
    // 执行一次，且第一次执行
    mounted() {
      this.init()
      this.first = true
    },
    // 组件被激活，第一次不执行
    activated() {
      // this.param父组件改变该属性值
      if (this.first) {
        this.first = false
        return
      }
      // 刷新数据
      this.search(this.param)
    },
    methods: {
      init() {
        // 刷新数据
        this.search(this.param)
        // 点击图片
        $('#blueimp-gallery').on('click', function() {
          $('body').addClass('overflowAuto')
        })
      },
      // 刷新表格数据
      search(requestSupportParams) {
        var _this = this
        // 详情页单独处理
        if (requestSupportParams.detail === 'true') {
          console.log('detail')
        }
        // 是否开启了附件上传功能
        this.isAttachment(this.param)
        // 加载审核详情列表
        var url = '/approval/getApprovalDetail.json?approvalId=' + requestSupportParams.approvalId
      },
      // 是否开启了附件上传功能
      isAttachment(requestSupportParams) {
        var _this = this
        var url = '/wf/attachment/enableAttachment.json?processId=' + requestSupportParams.processId
        kk.k_load_url('workflow', url, {}).then(rep => {
          rep = JSON.parse(rep)
          if (rep.status === '500') {
            _this.$message('附件列表加载失败')
          } else {
            if (rep.data === '1') {
              this.attachmentShow = true
            }
          }
        })
      },
      // 增加附件上传的功能，如果是详情页面，那么就不需要展示
      handleAttachmentButton() {
        console.log('后面写吧！这个功能不常用')
      }
    }
  }
</script>

<style scoped>
  /*让文本可以被选中*/
  .home {
    -moz-user-select: text; /*火狐*/
    -webkit-user-select: text; /*webkit浏览器*/
    -ms-user-select: text; /*IE10*/
    -khtml-user-select: text; /*早期浏览器*/
    user-select: text;
  }
  .wf_h {
    font-size: 18px;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.1;
    color: inherit;
  }
</style>
